{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "import pandas as pd\n",
    "from pandas import Series, DataFrame"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>country</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>abbrev</th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>AUS</th>\n",
       "      <td>Australia</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>AUT</th>\n",
       "      <td>Austria</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>BEL</th>\n",
       "      <td>Belgium</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>CAN</th>\n",
       "      <td>Canada</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>DNK</th>\n",
       "      <td>Denmark</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "          country\n",
       "abbrev           \n",
       "AUS     Australia\n",
       "AUT       Austria\n",
       "BEL       Belgium\n",
       "CAN        Canada\n",
       "DNK       Denmark"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Create a data frame, `oecd_df`, from `oecd_locations.csv`, containing a subset of all OECD countries.\n",
    "# The resulting data set should have a single column, called `country`. \n",
    "# The index should be based on the country's abbreviation.\n",
    "\n",
    "oecd_df = pd.read_csv('../data/oecd_locations.csv', header=None,\n",
    "                     names=['abbrev', 'country'],\n",
    "                     index_col='abbrev')\n",
    "oecd_df.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>TIME</th>\n",
       "      <th>Value</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>LOCATION</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>AUS</th>\n",
       "      <td>2008</td>\n",
       "      <td>27620.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>AUS</th>\n",
       "      <td>2009</td>\n",
       "      <td>25629.6</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>AUS</th>\n",
       "      <td>2010</td>\n",
       "      <td>31916.5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>AUS</th>\n",
       "      <td>2011</td>\n",
       "      <td>39381.5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>AUS</th>\n",
       "      <td>2012</td>\n",
       "      <td>41632.8</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "          TIME    Value\n",
       "LOCATION               \n",
       "AUS       2008  27620.0\n",
       "AUS       2009  25629.6\n",
       "AUS       2010  31916.5\n",
       "AUS       2011  39381.5\n",
       "AUS       2012  41632.8"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Create a second data frame, `oecd_tourism_df`, from `oecd_tourism.csv`. \n",
    "# We're only interested in three columns, namely `LOCATION` (which will serve as our index) \n",
    "# `TIME` (containing the year in which the measure was taken) and `Value` (the amount spent in each year).\n",
    "\n",
    "oecd_tourism_df = (\n",
    "    pd\n",
    "    .read_csv('../data/oecd_tourism.csv',\n",
    "              usecols=['LOCATION', 'TIME', 'Value', 'SUBJECT'],\n",
    "              index_col='LOCATION')\n",
    "    .loc[lambda df_: df_['SUBJECT'] == 'INT-EXP']\n",
    "    .drop('SUBJECT', axis='columns')\n",
    ")\n",
    "oecd_tourism_df.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "country\n",
       "Australia    36727.966667\n",
       "Austria      11934.563636\n",
       "Belgium      20859.883455\n",
       "Brazil       21564.351833\n",
       "Canada       40984.633333\n",
       "Name: Value, dtype: float64"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Create a new series, `tourism_spending`, in which the index reflects the \n",
    "# country names (i.e., not abbreviations), and the value contains\n",
    "# the average tourism spending for that country.\n",
    "\n",
    "tourism_spending = (\n",
    "    oecd_df\n",
    "    .join(oecd_tourism_df)\n",
    "    .groupby('country')['Value'].mean()\n",
    ")\n",
    "\n",
    "tourism_spending.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>country</th>\n",
       "      <th>points</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>US</td>\n",
       "      <td>96</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>Spain</td>\n",
       "      <td>96</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>US</td>\n",
       "      <td>96</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>US</td>\n",
       "      <td>96</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>France</td>\n",
       "      <td>95</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "  country  points\n",
       "0      US      96\n",
       "1   Spain      96\n",
       "2      US      96\n",
       "3      US      96\n",
       "4  France      95"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Create a third data frame, `wine_df`, based on `winemag-150k-reviews.csv`. \n",
    "# We only need two columns, `country` and `points`.\n",
    "\n",
    "wine_df = pd.read_csv('../data/winemag-150k-reviews.csv', \n",
    "                      usecols=['country', 'points'])\n",
    "wine_df.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "country\n",
       "Albania                   88.000000\n",
       "Argentina                 85.996093\n",
       "Australia                 87.892475\n",
       "Austria                   89.276742\n",
       "Bosnia and Herzegovina    84.750000\n",
       "Name: points, dtype: float64"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Get the mean wine score for each country, across all wine reviews, sorted in descending order.\n",
    "\n",
    "country_points = (\n",
    "    wine_df\n",
    "    .groupby('country')['points'].mean()\n",
    ")\n",
    "\n",
    "country_points.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "country\n",
       "England                   92.888889\n",
       "Austria                   89.276742\n",
       "France                    88.925870\n",
       "Germany                   88.626427\n",
       "Italy                     88.413664\n",
       "Canada                    88.239796\n",
       "Slovenia                  88.234043\n",
       "Morocco                   88.166667\n",
       "Turkey                    88.096154\n",
       "Portugal                  88.057685\n",
       "Albania                   88.000000\n",
       "US-France                 88.000000\n",
       "Australia                 87.892475\n",
       "US                        87.818789\n",
       "Serbia                    87.714286\n",
       "India                     87.625000\n",
       "New Zealand               87.554217\n",
       "Hungary                   87.329004\n",
       "Switzerland               87.250000\n",
       "South Africa              87.225421\n",
       "Israel                    87.176190\n",
       "Luxembourg                87.000000\n",
       "Spain                     86.646589\n",
       "Chile                     86.296768\n",
       "Croatia                   86.280899\n",
       "Greece                    86.117647\n",
       "Tunisia                   86.000000\n",
       "Argentina                 85.996093\n",
       "Cyprus                    85.870968\n",
       "Czech Republic            85.833333\n",
       "Lebanon                   85.702703\n",
       "Georgia                   85.511628\n",
       "Bulgaria                  85.467532\n",
       "Japan                     85.000000\n",
       "Romania                   84.920863\n",
       "Macedonia                 84.812500\n",
       "Mexico                    84.761905\n",
       "Bosnia and Herzegovina    84.750000\n",
       "Moldova                   84.718310\n",
       "Ukraine                   84.600000\n",
       "Uruguay                   84.478261\n",
       "Lithuania                 84.250000\n",
       "Slovakia                  83.666667\n",
       "Egypt                     83.666667\n",
       "Brazil                    83.240000\n",
       "Montenegro                82.000000\n",
       "China                     82.000000\n",
       "South Korea               81.500000\n",
       "Name: points, dtype: float64"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "country_points.sort_values(ascending=False)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>points</th>\n",
       "      <th>Value</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>country</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>Albania</th>\n",
       "      <td>88.000000</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Argentina</th>\n",
       "      <td>85.996093</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Australia</th>\n",
       "      <td>87.892475</td>\n",
       "      <td>36727.966667</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Austria</th>\n",
       "      <td>89.276742</td>\n",
       "      <td>11934.563636</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Bosnia and Herzegovina</th>\n",
       "      <td>84.750000</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Brazil</th>\n",
       "      <td>83.240000</td>\n",
       "      <td>21564.351833</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Bulgaria</th>\n",
       "      <td>85.467532</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Canada</th>\n",
       "      <td>88.239796</td>\n",
       "      <td>40984.633333</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Chile</th>\n",
       "      <td>86.296768</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>China</th>\n",
       "      <td>82.000000</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Croatia</th>\n",
       "      <td>86.280899</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Cyprus</th>\n",
       "      <td>85.870968</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Czech Republic</th>\n",
       "      <td>85.833333</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Egypt</th>\n",
       "      <td>83.666667</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>England</th>\n",
       "      <td>92.888889</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>France</th>\n",
       "      <td>88.925870</td>\n",
       "      <td>51394.272273</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Georgia</th>\n",
       "      <td>85.511628</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Germany</th>\n",
       "      <td>88.626427</td>\n",
       "      <td>96615.075545</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Greece</th>\n",
       "      <td>86.117647</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Hungary</th>\n",
       "      <td>87.329004</td>\n",
       "      <td>2918.390182</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>India</th>\n",
       "      <td>87.625000</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Israel</th>\n",
       "      <td>87.176190</td>\n",
       "      <td>6726.524833</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Italy</th>\n",
       "      <td>88.413664</td>\n",
       "      <td>34148.908455</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Japan</th>\n",
       "      <td>85.000000</td>\n",
       "      <td>32197.925000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Lebanon</th>\n",
       "      <td>85.702703</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Lithuania</th>\n",
       "      <td>84.250000</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Luxembourg</th>\n",
       "      <td>87.000000</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Macedonia</th>\n",
       "      <td>84.812500</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Mexico</th>\n",
       "      <td>84.761905</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Moldova</th>\n",
       "      <td>84.718310</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Montenegro</th>\n",
       "      <td>82.000000</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Morocco</th>\n",
       "      <td>88.166667</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>New Zealand</th>\n",
       "      <td>87.554217</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Portugal</th>\n",
       "      <td>88.057685</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Romania</th>\n",
       "      <td>84.920863</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Serbia</th>\n",
       "      <td>87.714286</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Slovakia</th>\n",
       "      <td>83.666667</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Slovenia</th>\n",
       "      <td>88.234043</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>South Africa</th>\n",
       "      <td>87.225421</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>South Korea</th>\n",
       "      <td>81.500000</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Spain</th>\n",
       "      <td>86.646589</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Switzerland</th>\n",
       "      <td>87.250000</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Tunisia</th>\n",
       "      <td>86.000000</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Turkey</th>\n",
       "      <td>88.096154</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>US</th>\n",
       "      <td>87.818789</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>US-France</th>\n",
       "      <td>88.000000</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Ukraine</th>\n",
       "      <td>84.600000</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Uruguay</th>\n",
       "      <td>84.478261</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                           points         Value\n",
       "country                                        \n",
       "Albania                 88.000000           NaN\n",
       "Argentina               85.996093           NaN\n",
       "Australia               87.892475  36727.966667\n",
       "Austria                 89.276742  11934.563636\n",
       "Bosnia and Herzegovina  84.750000           NaN\n",
       "Brazil                  83.240000  21564.351833\n",
       "Bulgaria                85.467532           NaN\n",
       "Canada                  88.239796  40984.633333\n",
       "Chile                   86.296768           NaN\n",
       "China                   82.000000           NaN\n",
       "Croatia                 86.280899           NaN\n",
       "Cyprus                  85.870968           NaN\n",
       "Czech Republic          85.833333           NaN\n",
       "Egypt                   83.666667           NaN\n",
       "England                 92.888889           NaN\n",
       "France                  88.925870  51394.272273\n",
       "Georgia                 85.511628           NaN\n",
       "Germany                 88.626427  96615.075545\n",
       "Greece                  86.117647           NaN\n",
       "Hungary                 87.329004   2918.390182\n",
       "India                   87.625000           NaN\n",
       "Israel                  87.176190   6726.524833\n",
       "Italy                   88.413664  34148.908455\n",
       "Japan                   85.000000  32197.925000\n",
       "Lebanon                 85.702703           NaN\n",
       "Lithuania               84.250000           NaN\n",
       "Luxembourg              87.000000           NaN\n",
       "Macedonia               84.812500           NaN\n",
       "Mexico                  84.761905           NaN\n",
       "Moldova                 84.718310           NaN\n",
       "Montenegro              82.000000           NaN\n",
       "Morocco                 88.166667           NaN\n",
       "New Zealand             87.554217           NaN\n",
       "Portugal                88.057685           NaN\n",
       "Romania                 84.920863           NaN\n",
       "Serbia                  87.714286           NaN\n",
       "Slovakia                83.666667           NaN\n",
       "Slovenia                88.234043           NaN\n",
       "South Africa            87.225421           NaN\n",
       "South Korea             81.500000           NaN\n",
       "Spain                   86.646589           NaN\n",
       "Switzerland             87.250000           NaN\n",
       "Tunisia                 86.000000           NaN\n",
       "Turkey                  88.096154           NaN\n",
       "US                      87.818789           NaN\n",
       "US-France               88.000000           NaN\n",
       "Ukraine                 84.600000           NaN\n",
       "Uruguay                 84.478261           NaN"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Perform a standard join between the average wine scores per country and \n",
    "# the average tourism spending per country. Where do you see `NaN` values? \n",
    "# What do those `NaN` values mean?\n",
    "\n",
    "country_points.to_frame().join(tourism_spending)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>points</th>\n",
       "      <th>Value</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>country</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>Albania</th>\n",
       "      <td>88.000000</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Argentina</th>\n",
       "      <td>85.996093</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Australia</th>\n",
       "      <td>87.892475</td>\n",
       "      <td>36727.966667</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Austria</th>\n",
       "      <td>89.276742</td>\n",
       "      <td>11934.563636</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Belgium</th>\n",
       "      <td>NaN</td>\n",
       "      <td>20859.883455</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Bosnia and Herzegovina</th>\n",
       "      <td>84.750000</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Brazil</th>\n",
       "      <td>83.240000</td>\n",
       "      <td>21564.351833</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Bulgaria</th>\n",
       "      <td>85.467532</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Canada</th>\n",
       "      <td>88.239796</td>\n",
       "      <td>40984.633333</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Chile</th>\n",
       "      <td>86.296768</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>China</th>\n",
       "      <td>82.000000</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Croatia</th>\n",
       "      <td>86.280899</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Cyprus</th>\n",
       "      <td>85.870968</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Czech Republic</th>\n",
       "      <td>85.833333</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Denmark</th>\n",
       "      <td>NaN</td>\n",
       "      <td>11326.169636</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Egypt</th>\n",
       "      <td>83.666667</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>England</th>\n",
       "      <td>92.888889</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Finland</th>\n",
       "      <td>NaN</td>\n",
       "      <td>5877.080909</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>France</th>\n",
       "      <td>88.925870</td>\n",
       "      <td>51394.272273</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Georgia</th>\n",
       "      <td>85.511628</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Germany</th>\n",
       "      <td>88.626427</td>\n",
       "      <td>96615.075545</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Greece</th>\n",
       "      <td>86.117647</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Hungary</th>\n",
       "      <td>87.329004</td>\n",
       "      <td>2918.390182</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>India</th>\n",
       "      <td>87.625000</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Israel</th>\n",
       "      <td>87.176190</td>\n",
       "      <td>6726.524833</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Italy</th>\n",
       "      <td>88.413664</td>\n",
       "      <td>34148.908455</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Japan</th>\n",
       "      <td>85.000000</td>\n",
       "      <td>32197.925000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Korea</th>\n",
       "      <td>NaN</td>\n",
       "      <td>25573.509091</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Lebanon</th>\n",
       "      <td>85.702703</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Lithuania</th>\n",
       "      <td>84.250000</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Luxembourg</th>\n",
       "      <td>87.000000</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Macedonia</th>\n",
       "      <td>84.812500</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Mexico</th>\n",
       "      <td>84.761905</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Moldova</th>\n",
       "      <td>84.718310</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Montenegro</th>\n",
       "      <td>82.000000</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Morocco</th>\n",
       "      <td>88.166667</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>New Zealand</th>\n",
       "      <td>87.554217</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Portugal</th>\n",
       "      <td>88.057685</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Romania</th>\n",
       "      <td>84.920863</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Serbia</th>\n",
       "      <td>87.714286</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Slovakia</th>\n",
       "      <td>83.666667</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Slovenia</th>\n",
       "      <td>88.234043</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>South Africa</th>\n",
       "      <td>87.225421</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>South Korea</th>\n",
       "      <td>81.500000</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Spain</th>\n",
       "      <td>86.646589</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Switzerland</th>\n",
       "      <td>87.250000</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Tunisia</th>\n",
       "      <td>86.000000</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Turkey</th>\n",
       "      <td>88.096154</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>US</th>\n",
       "      <td>87.818789</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>US-France</th>\n",
       "      <td>88.000000</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Ukraine</th>\n",
       "      <td>84.600000</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>United Kingdom</th>\n",
       "      <td>NaN</td>\n",
       "      <td>75262.227273</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>United States</th>\n",
       "      <td>NaN</td>\n",
       "      <td>142080.666667</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Uruguay</th>\n",
       "      <td>84.478261</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                           points          Value\n",
       "country                                         \n",
       "Albania                 88.000000            NaN\n",
       "Argentina               85.996093            NaN\n",
       "Australia               87.892475   36727.966667\n",
       "Austria                 89.276742   11934.563636\n",
       "Belgium                       NaN   20859.883455\n",
       "Bosnia and Herzegovina  84.750000            NaN\n",
       "Brazil                  83.240000   21564.351833\n",
       "Bulgaria                85.467532            NaN\n",
       "Canada                  88.239796   40984.633333\n",
       "Chile                   86.296768            NaN\n",
       "China                   82.000000            NaN\n",
       "Croatia                 86.280899            NaN\n",
       "Cyprus                  85.870968            NaN\n",
       "Czech Republic          85.833333            NaN\n",
       "Denmark                       NaN   11326.169636\n",
       "Egypt                   83.666667            NaN\n",
       "England                 92.888889            NaN\n",
       "Finland                       NaN    5877.080909\n",
       "France                  88.925870   51394.272273\n",
       "Georgia                 85.511628            NaN\n",
       "Germany                 88.626427   96615.075545\n",
       "Greece                  86.117647            NaN\n",
       "Hungary                 87.329004    2918.390182\n",
       "India                   87.625000            NaN\n",
       "Israel                  87.176190    6726.524833\n",
       "Italy                   88.413664   34148.908455\n",
       "Japan                   85.000000   32197.925000\n",
       "Korea                         NaN   25573.509091\n",
       "Lebanon                 85.702703            NaN\n",
       "Lithuania               84.250000            NaN\n",
       "Luxembourg              87.000000            NaN\n",
       "Macedonia               84.812500            NaN\n",
       "Mexico                  84.761905            NaN\n",
       "Moldova                 84.718310            NaN\n",
       "Montenegro              82.000000            NaN\n",
       "Morocco                 88.166667            NaN\n",
       "New Zealand             87.554217            NaN\n",
       "Portugal                88.057685            NaN\n",
       "Romania                 84.920863            NaN\n",
       "Serbia                  87.714286            NaN\n",
       "Slovakia                83.666667            NaN\n",
       "Slovenia                88.234043            NaN\n",
       "South Africa            87.225421            NaN\n",
       "South Korea             81.500000            NaN\n",
       "Spain                   86.646589            NaN\n",
       "Switzerland             87.250000            NaN\n",
       "Tunisia                 86.000000            NaN\n",
       "Turkey                  88.096154            NaN\n",
       "US                      87.818789            NaN\n",
       "US-France               88.000000            NaN\n",
       "Ukraine                 84.600000            NaN\n",
       "United Kingdom                NaN   75262.227273\n",
       "United States                 NaN  142080.666667\n",
       "Uruguay                 84.478261            NaN"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Now perform an outer join between the average wine scores per country\n",
    "# and the average tourism spending per country. \n",
    "# Where do you see `NaN` values? What do they mean now?\n",
    "\n",
    "country_points.to_frame().join(tourism_spending, how='outer')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>points</th>\n",
       "      <th>Value</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>points</th>\n",
       "      <td>1.000000</td>\n",
       "      <td>0.288231</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Value</th>\n",
       "      <td>0.288231</td>\n",
       "      <td>1.000000</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "          points     Value\n",
       "points  1.000000  0.288231\n",
       "Value   0.288231  1.000000"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Find the correlation between average wine score and average tourism spending. \n",
    "# What can you say about these two values?  Is there any correlation?\n",
    "\n",
    "country_points.to_frame().join(tourism_spending, how='outer').corr()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.11.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
